import { defineStore } from 'pinia'
export const searchStore = defineStore('searchStore', {
    state: () => {
        return {
            history: [],
            goodsList: '',
        }
    },
    actions: {
        // 设置搜索到信息
        setHistory(history) {
            this.history = history
        },
        updateHistory(obj) {
            // 数组去重并且排序
            let arr = Array.from(new Set([...obj, ...this.history]))
            this.history = arr
        },
        // 删除某个历史记录
        removeHistory(index) {
            this.history.splice(index, 1)
        },
        // 设置搜索到信息
        setGoodsList(goodsList) {
            this.goodsList = ''
            this.goodsList = goodsList
        },
    },
    persist: {
        // 开启数据持久化
        enabled: true,
        strategies: [
            {
                // 保存的名称
                key: 'searchManage',
                storage: localStorage,
            },
        ],
    },
})
